﻿package mortal.game.view.group
{
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.events.*;
    import com.mui.utils.*;
    import extend.language.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.group.panel.*;
    import mortal.game.view.wizard.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GroupMoudle extends BaseWindow
    {
        private var _tabData:Array;
        private var _tabBar:GTabarNew;
        private var _currentPanel:GSprite;

        public function GroupMoudle(param1:ILayer = null)
        {
            this._tabData = Language.getArray(30200);
            super(param1);
            this.init();
            this.layer = LayerManager.windowLayer3D;
            return;
        }// end function

        private function init() : void
        {
            _titleHeight = 35;
            setSize(795, 451);
            title = Language.getString(30201);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._tabBar = UIFactory.gTabBarNew(3, 33, this._tabData, 795, 451, 64, 24, this, this.onTabBarSelectedChange);
            this._tabBar.selectedIndex = 0;
            LoaderHelp.addResCallBack(ResFileConst.groupPanel, this.onGetRes);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._tabBar.dispose(param1);
            if (this._currentPanel)
            {
                this._currentPanel.dispose(param1);
                this._currentPanel = null;
            }
            this._tabBar = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function onGetRes() : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GroupPanel_ViewInited));
            return;
        }// end function

        private function addTeamInfoPanel() : TeamInfoPanel
        {
            var _loc_1:TeamInfoPanel = null;
            _loc_1 = UICompomentPool.getUICompoment(TeamInfoPanel, this);
            _loc_1.x = -3;
            addChild(_loc_1);
            return _loc_1;
        }// end function

        private function addNearPlayerPanel() : NearPlayerPanel
        {
            var _loc_1:* = UICompomentPool.getUICompoment(NearPlayerPanel);
            _loc_1.x = -3;
            addChild(_loc_1);
            return _loc_1;
        }// end function

        private function addNearTeamPanel() : NearTeamsPanel
        {
            var _loc_1:* = UICompomentPool.getUICompoment(NearTeamsPanel);
            _loc_1.x = -3;
            addChild(_loc_1);
            return _loc_1;
        }// end function

        private function addInvitePanel() : GroupInvitePanel
        {
            var _loc_1:* = UICompomentPool.getUICompoment(GroupInvitePanel);
            _loc_1.x = -3;
            addChild(_loc_1);
            return _loc_1;
        }// end function

        private function addApplyPanel() : GroupApplyPanel
        {
            var _loc_1:GroupApplyPanel = null;
            _loc_1 = UICompomentPool.getUICompoment(GroupApplyPanel);
            _loc_1.x = -3;
            addChild(_loc_1);
            return _loc_1;
        }// end function

        private function onTabBarSelectedChange(event:MuiEvent) : void
        {
            this.changeTabBarByIndex(this._tabBar.selectedIndex);
            return;
        }// end function

        public function changeTabBarByIndex(param1:int) : void
        {
            if (this._currentPanel)
            {
                this._currentPanel.dispose();
            }
            switch(param1)
            {
                case 0:
                {
                    this._currentPanel = this.addTeamInfoPanel();
                    break;
                }
                case 1:
                {
                    this._currentPanel = this.addNearTeamPanel();
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GroupGetNearTeam));
                    break;
                }
                case 2:
                {
                    this._currentPanel = this.addNearPlayerPanel();
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GroupGetNearPlayer));
                    break;
                }
                case 3:
                {
                    this._currentPanel = this.addApplyPanel();
                    break;
                }
                case 4:
                {
                    this._currentPanel = this.addInvitePanel();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function getNearGroupIdArr() : void
        {
            return;
        }// end function

        public function showSkin() : void
        {
            if (isDisposed)
            {
                return;
            }
            if (this._tabBar.selectedIndex != 0)
            {
                return;
            }
            this.changeTabBarByIndex(0);
            return;
        }// end function

        public function updateTeamMate() : void
        {
            if (this._currentPanel is TeamInfoPanel)
            {
                (this._currentPanel as TeamInfoPanel).updateTeamMate();
            }
            return;
        }// end function

        public function updateNearPlayer() : void
        {
            if (this._currentPanel is NearPlayerPanel)
            {
                (this._currentPanel as NearPlayerPanel).updatePlayerList();
            }
            return;
        }// end function

        public function updateNearTeam() : void
        {
            if (this._currentPanel is NearTeamsPanel)
            {
                (this._currentPanel as NearTeamsPanel).updateTeamList();
            }
            return;
        }// end function

        public function updateInviteList() : void
        {
            if (this._currentPanel is GroupInvitePanel)
            {
                (this._currentPanel as GroupInvitePanel).updateInviteList();
            }
            return;
        }// end function

        public function updateApplyList() : void
        {
            if (this._currentPanel is GroupApplyPanel)
            {
                (this._currentPanel as GroupApplyPanel).updateApplyList();
            }
            return;
        }// end function

        public function changeTabIndex(param1:int) : void
        {
            this._tabBar.selectedIndex = param1;
            this.changeTabBarByIndex(param1);
            return;
        }// end function

        public function updateSetting() : void
        {
            if (this._currentPanel is TeamInfoPanel)
            {
                (this._currentPanel as TeamInfoPanel).updateSetting();
            }
            return;
        }// end function

    }
}
